﻿namespace OleDbDAL.Procurement
{
    using DBUtility;
    using IDal.Procurement;
    using Model.Procurement;
    using System;
    using System.Data;
    using System.Text;

    public class ProcurementApp : IProcurement
    {
        private string dbname = "Systems";

        public void Add(ProcurementEnt model)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("insert into T_Procurement(");
            builder.Append("IDDocuments,SupplierId,ChainNum,AccountId,ToMeetMoney,PaidMoney,LogisticsId,LogisticsName,LogisticsNum,IsInvoicing,InvoicingNum,InvoicingTime,CreateTime,ProcuMan,ProcuTime,IsNeedCheck,CheckMan,CheckTime,IsAccep,AccepMan,AccepTime,IsRejection,CreateMan,RejectionTime,RejectionReason,IsReview,ReviewMan,ReviewTime,ReviewReason,IsUseReturn,ReturnMoney,ReturnReason,shippersMan,Tel,ReturnType,IsInput,OpenType,OrderId,PlanTime,IsClearIngAll,IsRequestReturn,IsBlackOut,Remark");
            builder.Append(")");
            builder.Append(" values (");
            builder.Append("'" + model.IDDocuments + "',");
            builder.Append("" + model.SupplierId + ",");
            builder.Append("" + model.ChainNum + ",");
            builder.Append("" + model.AccountId + ",");
            builder.Append("" + model.ToMeetMoney + ",");
            builder.Append("" + model.PaidMoney + ",");
            builder.Append("" + model.LogisticsId + ",");
            builder.Append("'" + model.LogisticsName + "',");
            builder.Append("'" + model.LogisticsNum + "',");
            builder.Append("" + model.IsInvoicing + ",");
            builder.Append("'" + model.InvoicingNum + "',");
            builder.Append("'" + model.InvoicingTime + "',");
            builder.Append("'" + model.CreateTime + "',");
            builder.Append("" + model.ProcuMan + ",");
            builder.Append("'" + model.ProcuTime + "',");
            builder.Append("" + model.IsNeedCheck + ",");
            builder.Append("" + model.CheckMan + ",");
            builder.Append("'" + model.CheckTime + "',");
            builder.Append("" + model.IsAccep + ",");
            builder.Append("" + model.AccepMan + ",");
            builder.Append("'" + model.AccepTime + "',");
            builder.Append("" + model.IsRejection + ",");
            builder.Append("" + model.CreateMan + ",");
            builder.Append("'" + model.RejectionTime + "',");
            builder.Append("'" + model.RejectionReason + "',");
            builder.Append("" + model.IsReview + ",");
            builder.Append("'" + model.ReviewMan + "',");
            builder.Append("'" + model.ReviewTime + "',");
            builder.Append("'" + model.ReviewReason + "',");
            builder.Append("" + model.IsUseReturn + ",");
            builder.Append("" + model.ReturnMoney + ",");
            builder.Append("'" + model.ReturnReason + "',");
            builder.Append("" + model.shippersMan + ",");
            builder.Append("'" + model.Tel + "',");
            builder.Append("" + model.ReturnType + ",");
            builder.Append("" + model.IsInput + ",");
            builder.Append("" + model.OpenType + ",");
            builder.Append("" + model.OrderId + ",");
            builder.Append("'" + model.PlanTime + "',");
            builder.Append("" + model.IsClearIngAll + ",");
            builder.Append("" + model.IsRequestReturn + ",");
            builder.Append("" + model.IsBlackOut + ",");
            builder.Append("'" + model.Remark + "'");
            builder.Append(")");
            DbHelperOledb.ExecuteSql(this.dbname, builder.ToString());
        }

        public void Delete(int ProcurementId)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("delete from T_Procurement ");
            builder.Append(" where ProcurementId=" + ProcurementId);
            DbHelperOledb.ExecuteSql(this.dbname, builder.ToString());
        }

        public bool FuCheck(ProcurementEnt model)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("update T_Procurement set ");
            builder.Append("ReviewMan=" + model.ReviewMan + ",");
            builder.Append("ReviewTime='" + model.ReviewTime + "',");
            builder.Append("IsReview=" + model.IsReview + ",");
            builder.Append("IsInput=" + model.IsInput + ",");
            builder.Append("ReviewReason='" + model.ReviewReason + "'");
            builder.Append(" where ProcurementId=" + model.ProcurementId + "");
            DbHelperOledb.ExecuteSql(this.dbname, builder.ToString());
            return true;
        }

        public DataTable GetList(string strWhere)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("select * from T_Procurement ");
            if (strWhere.Trim() != "")
            {
                builder.Append(" where " + strWhere);
            }
            builder.Append(" order by ProcurementId ");
            return DbHelperOledb.Query(this.dbname, builder.ToString());
        }

        public int GetMaxId(string swhere)
        {
            return DbHelperOledb.GetMaxID(this.dbname, "ProcurementId", "T_Procurement", swhere);
        }

        public ProcurementEnt GetModel(int ProcurementId)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("select ProcurementId,IDDocuments,SupplierId,ChainNum,AccountId,ToMeetMoney,PaidMoney,LogisticsId,LogisticsName,LogisticsNum,IsInvoicing,InvoicingNum,InvoicingTime,CreateTime,ProcuMan,ProcuTime,IsNeedCheck,CheckMan,CheckTime,IsAccep,AccepMan,AccepTime,IsRejection,CreateMan,RejectionTime,RejectionReason,IsReview,ReviewMan,ReviewTime,ReviewReason,IsUseReturn,ReturnMoney,ReturnReason,shippersMan,Tel,ReturnType,IsInput,OpenType,OrderId,PlanTime,IsClearIngAll,IsRequestReturn,IsBlackOut,BlackManId,BlackManName,BlackTime,Remark from T_Procurement ");
            builder.Append(" where ProcurementId=" + ProcurementId);
            ProcurementEnt ent = new ProcurementEnt();
            DataTable table = DbHelperOledb.Query(this.dbname, builder.ToString());
            ent.ProcurementId = ProcurementId;
            if (table.Rows.Count > 0)
            {
                ent.IDDocuments = table.Rows[0]["IDDocuments"].ToString();
                if (table.Rows[0]["SupplierId"].ToString() != "")
                {
                    ent.SupplierId = int.Parse(table.Rows[0]["SupplierId"].ToString());
                }
                if (table.Rows[0]["ChainNum"].ToString() != "")
                {
                    ent.ChainNum = int.Parse(table.Rows[0]["ChainNum"].ToString());
                }
                if (table.Rows[0]["AccountId"].ToString() != "")
                {
                    ent.AccountId = int.Parse(table.Rows[0]["AccountId"].ToString());
                }
                if (table.Rows[0]["ToMeetMoney"].ToString() != "")
                {
                    ent.ToMeetMoney = decimal.Parse(table.Rows[0]["ToMeetMoney"].ToString());
                }
                if (table.Rows[0]["PaidMoney"].ToString() != "")
                {
                    ent.PaidMoney = decimal.Parse(table.Rows[0]["PaidMoney"].ToString());
                }
                if (table.Rows[0]["LogisticsId"].ToString() != "")
                {
                    ent.LogisticsId = int.Parse(table.Rows[0]["LogisticsId"].ToString());
                }
                ent.LogisticsName = table.Rows[0]["LogisticsName"].ToString();
                ent.LogisticsNum = table.Rows[0]["LogisticsNum"].ToString();
                if (table.Rows[0]["IsInvoicing"].ToString() != "")
                {
                    ent.IsInvoicing = int.Parse(table.Rows[0]["IsInvoicing"].ToString());
                }
                ent.InvoicingNum = table.Rows[0]["InvoicingNum"].ToString();
                if (table.Rows[0]["InvoicingTime"].ToString() != "")
                {
                    ent.InvoicingTime = DateTime.Parse(table.Rows[0]["InvoicingTime"].ToString());
                }
                if (table.Rows[0]["CreateTime"].ToString() != "")
                {
                    ent.CreateTime = DateTime.Parse(table.Rows[0]["CreateTime"].ToString());
                }
                if (table.Rows[0]["ProcuMan"].ToString() != "")
                {
                    ent.ProcuMan = int.Parse(table.Rows[0]["ProcuMan"].ToString());
                }
                if (table.Rows[0]["ProcuTime"].ToString() != "")
                {
                    ent.ProcuTime = DateTime.Parse(table.Rows[0]["ProcuTime"].ToString());
                }
                if (table.Rows[0]["IsNeedCheck"].ToString() != "")
                {
                    ent.IsNeedCheck = int.Parse(table.Rows[0]["IsNeedCheck"].ToString());
                }
                if (table.Rows[0]["CheckMan"].ToString() != "")
                {
                    ent.CheckMan = int.Parse(table.Rows[0]["CheckMan"].ToString());
                }
                if (table.Rows[0]["CheckTime"].ToString() != "")
                {
                    ent.CheckTime = DateTime.Parse(table.Rows[0]["CheckTime"].ToString());
                }
                if (table.Rows[0]["IsAccep"].ToString() != "")
                {
                    ent.IsAccep = int.Parse(table.Rows[0]["IsAccep"].ToString());
                }
                if (table.Rows[0]["AccepMan"].ToString() != "")
                {
                    ent.AccepMan = int.Parse(table.Rows[0]["AccepMan"].ToString());
                }
                if (table.Rows[0]["AccepTime"].ToString() != "")
                {
                    ent.AccepTime = DateTime.Parse(table.Rows[0]["AccepTime"].ToString());
                }
                if (table.Rows[0]["IsRejection"].ToString() != "")
                {
                    ent.IsRejection = int.Parse(table.Rows[0]["IsRejection"].ToString());
                }
                if (table.Rows[0]["CreateMan"].ToString() != "")
                {
                    ent.CreateMan = int.Parse(table.Rows[0]["CreateMan"].ToString());
                }
                if (table.Rows[0]["RejectionTime"].ToString() != "")
                {
                    ent.RejectionTime = DateTime.Parse(table.Rows[0]["RejectionTime"].ToString());
                }
                ent.RejectionReason = table.Rows[0]["RejectionReason"].ToString();
                if (table.Rows[0]["IsReview"].ToString() != "")
                {
                    ent.IsReview = int.Parse(table.Rows[0]["IsReview"].ToString());
                }
                ent.ReviewMan = table.Rows[0]["ReviewMan"].ToString();
                if (table.Rows[0]["ReviewTime"].ToString() != "")
                {
                    ent.ReviewTime = DateTime.Parse(table.Rows[0]["ReviewTime"].ToString());
                }
                ent.ReviewReason = table.Rows[0]["ReviewReason"].ToString();
                if (table.Rows[0]["IsUseReturn"].ToString() != "")
                {
                    ent.IsUseReturn = int.Parse(table.Rows[0]["IsUseReturn"].ToString());
                }
                if (table.Rows[0]["ReturnMoney"].ToString() != "")
                {
                    ent.ReturnMoney = decimal.Parse(table.Rows[0]["ReturnMoney"].ToString());
                }
                ent.ReturnReason = table.Rows[0]["ReturnReason"].ToString();
                if (table.Rows[0]["shippersMan"].ToString() != "")
                {
                    ent.shippersMan = int.Parse(table.Rows[0]["shippersMan"].ToString());
                }
                ent.Tel = table.Rows[0]["Tel"].ToString();
                if (table.Rows[0]["ReturnType"].ToString() != "")
                {
                    ent.ReturnType = int.Parse(table.Rows[0]["ReturnType"].ToString());
                }
                if (table.Rows[0]["IsInput"].ToString() != "")
                {
                    ent.IsInput = int.Parse(table.Rows[0]["IsInput"].ToString());
                }
                if (table.Rows[0]["OpenType"].ToString() != "")
                {
                    ent.OpenType = int.Parse(table.Rows[0]["OpenType"].ToString());
                }
                if (table.Rows[0]["OrderId"].ToString() != "")
                {
                    ent.OrderId = int.Parse(table.Rows[0]["OrderId"].ToString());
                }
                if (table.Rows[0]["PlanTime"].ToString() != "")
                {
                    ent.PlanTime = DateTime.Parse(table.Rows[0]["PlanTime"].ToString());
                }
                if (table.Rows[0]["IsClearIngAll"].ToString() != "")
                {
                    ent.IsClearIngAll = int.Parse(table.Rows[0]["IsClearIngAll"].ToString());
                }
                if (table.Rows[0]["IsRequestReturn"].ToString() != "")
                {
                    ent.IsRequestReturn = int.Parse(table.Rows[0]["IsRequestReturn"].ToString());
                }
                if (table.Rows[0]["IsBlackOut"].ToString() != "")
                {
                    ent.IsBlackOut = int.Parse(table.Rows[0]["IsBlackOut"].ToString());
                }
                if (table.Rows[0]["BlackManId"].ToString() != "")
                {
                    ent.BlackManId = int.Parse(table.Rows[0]["BlackManId"].ToString());
                }
                ent.BlackManName = table.Rows[0]["BlackManName"].ToString();
                if (table.Rows[0]["BlackTime"].ToString() != "")
                {
                    ent.BlackTime = DateTime.Parse(table.Rows[0]["BlackTime"].ToString());
                }
                ent.Remark = table.Rows[0]["Remark"].ToString();
                return ent;
            }
            return null;
        }

        public DataTable GetPageList(int PageSize, int PageIndex, string strWhere)
        {
            string orderString = "";
            int pageCount = 0;
            int recordCount = 0;
            StringBuilder builder = new StringBuilder();
            builder.Append("select * from T_Procurement ");
            return DbHelperOledb.ExecutePager(this.dbname, PageIndex, PageSize, "", builder.ToString(), strWhere, orderString, out pageCount, out recordCount, "ProcurementId");
        }

        public void Update(ProcurementEnt model)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("update T_Procurement set ");
            builder.Append("IDDocuments='" + model.IDDocuments + "',");
            builder.Append("SupplierId=" + model.SupplierId + ",");
            builder.Append("ChainNum=" + model.ChainNum + ",");
            builder.Append("AccountId=" + model.AccountId + ",");
            builder.Append("ToMeetMoney=" + model.ToMeetMoney + ",");
            builder.Append("PaidMoney=" + model.PaidMoney + ",");
            builder.Append("LogisticsId=" + model.LogisticsId + ",");
            builder.Append("LogisticsName='" + model.LogisticsName + "',");
            builder.Append("LogisticsNum='" + model.LogisticsNum + "',");
            builder.Append("IsInvoicing=" + model.IsInvoicing + ",");
            builder.Append("InvoicingNum='" + model.InvoicingNum + "',");
            builder.Append("InvoicingTime='" + model.InvoicingTime + "',");
            builder.Append("CreateTime='" + model.CreateTime + "',");
            builder.Append("ProcuMan=" + model.ProcuMan + ",");
            builder.Append("ProcuTime='" + model.ProcuTime + "',");
            builder.Append("IsNeedCheck=" + model.IsNeedCheck + ",");
            builder.Append("CheckMan=" + model.CheckMan + ",");
            builder.Append("CheckTime='" + model.CheckTime + "',");
            builder.Append("IsAccep=" + model.IsAccep + ",");
            builder.Append("AccepMan=" + model.AccepMan + ",");
            builder.Append("AccepTime='" + model.AccepTime + "',");
            builder.Append("IsRejection=" + model.IsRejection + ",");
            builder.Append("CreateMan=" + model.CreateMan + ",");
            builder.Append("RejectionTime='" + model.RejectionTime + "',");
            builder.Append("RejectionReason='" + model.RejectionReason + "',");
            builder.Append("IsReview=" + model.IsReview + ",");
            builder.Append("ReviewMan='" + model.ReviewMan + "',");
            builder.Append("ReviewTime='" + model.ReviewTime + "',");
            builder.Append("ReviewReason='" + model.ReviewReason + "',");
            builder.Append("IsUseReturn=" + model.IsUseReturn + ",");
            builder.Append("ReturnMoney=" + model.ReturnMoney + ",");
            builder.Append("ReturnReason='" + model.ReturnReason + "',");
            builder.Append("shippersMan=" + model.shippersMan + ",");
            builder.Append("Tel='" + model.Tel + "',");
            builder.Append("ReturnType=" + model.ReturnType + ",");
            builder.Append("IsInput=" + model.IsInput + ",");
            builder.Append("OpenType=" + model.OpenType + ",");
            builder.Append("OrderId=" + model.OrderId + ",");
            builder.Append("PlanTime='" + model.PlanTime + "',");
            builder.Append("IsClearIngAll=" + model.IsClearIngAll + ",");
            builder.Append("IsRequestReturn=" + model.IsRequestReturn + ",");
            builder.Append("IsBlackOut=" + model.IsBlackOut + ",");
            builder.Append("Remark='" + model.Remark + "'");
            builder.Append(" where ProcurementId=" + model.ProcurementId + "");
            DbHelperOledb.ExecuteSql(this.dbname, builder.ToString());
        }

        public void UpdateZuoFei(ProcurementEnt model)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("update T_Procurement set ");
            builder.Append("IsBlackOut=" + model.IsBlackOut + ",");
            builder.Append("BlackManId=" + model.BlackManId + ",");
            builder.Append("BlackManName='" + model.BlackManName + "',");
            builder.Append("BlackTime='" + model.BlackTime + "'");
            builder.Append(" where ProcurementId=" + model.ProcurementId + "");
            DbHelperOledb.ExecuteSql(this.dbname, builder.ToString());
        }
    }
}

